package com.dinzeer.lostbladereborn.se;


import com.dinzeer.legendreliclib.lib.StackReg;
import com.dinzeer.legendreliclib.lib.util.text.AdvancedGradientTextHelper;
import com.dinzeer.legendreliclib.lib.util.text.ColorPreset;
import com.dinzeer.lostbladereborn.regsitry.LBRSpecialEffectRegsitry;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.event.SlashBladeEvent;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class StarsSE extends SpecialEffectEx {

    public StarsSE() {
        super(30);
    }
    //todo what

   

    @SubscribeEvent
    public static void onupdate(SlashBladeEvent.UpdateEvent event) {
        ISlashBladeState state = event.getSlashBladeState();
        if (event.getEntity() instanceof Player player) {
            if (!event.isSelected())
                return;
            if (state.hasSpecialEffect(LBRSpecialEffectRegsitry.Dubhe.getId())) {

                int level = player.experienceLevel;
                if (SpecialEffect.isEffective(LBRSpecialEffectRegsitry.Dubhe.get(), level)) {
                    if (StackReg.COMBO_NUMBER.getCurrentStacks(player) < 10) {
                        player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 0));
                    }
                    if (StackReg.COMBO_NUMBER.getCurrentStacks(player) >= 10 && StackReg.COMBO_NUMBER.getCurrentStacks(player) < 100) {
                        player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 1));
                    }
                    if (StackReg.COMBO_NUMBER.getCurrentStacks(player) >= 100) {
                        player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 2));
                    }

                }
            }
            if (state.hasSpecialEffect(LBRSpecialEffectRegsitry.Hagen.getId())) {

                int level = player.experienceLevel;
                if (SpecialEffect.isEffective(LBRSpecialEffectRegsitry.Hagen.get(), level)) {
                    if (StackReg.COMBO_NUMBER.getCurrentStacks(player) < 10) {
                        player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 100, 0));
                    }
                    if (StackReg.COMBO_NUMBER.getCurrentStacks(player) >= 10 && StackReg.COMBO_NUMBER.getCurrentStacks(player) < 100) {
                        player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 100, 1));
                    }
                    if (StackReg.COMBO_NUMBER.getCurrentStacks(player) >= 100) {
                        player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 100, 2));
                    }

                }
            }
            if (hasSpecialEffect2(event.getBlade(), LBRSpecialEffectRegsitry.Alkaid.getId(), player)) {
                if (StackReg.COMBO_NUMBER.getCurrentStacks(player) < 10) {
                    player.addEffect(new MobEffectInstance(MobEffects.LUCK, 100, 1));
                }
                if (StackReg.COMBO_NUMBER.getCurrentStacks(player) >= 10) {
                    player.addEffect(new MobEffectInstance(MobEffects.LUCK, 100, 2));
                }
            }

        }
    }


    @SubscribeEvent
    public static void Megrez(LivingDeathEvent event) {
        if (event.getSource().getEntity() instanceof Player player) {
            if (hasSpecialEffect2(player.getMainHandItem(), LBRSpecialEffectRegsitry.Megrez.getId(), player)) {
                double d = 0.5f;
                if (StackReg.COMBO_NUMBER.getCurrentStacks(player) > 10) {
                    d = 1;
                }
                event.getEntity().getPersistentData().putDouble("bootXpDrop", d);
            }
        }
    }

    @SubscribeEvent
    public static void Fenrir(LivingDeathEvent event) {
        if (event.getSource().getEntity() instanceof Player player) {
            if (hasSpecialEffect2(player.getMainHandItem(), LBRSpecialEffectRegsitry.Fenrir.getId(), player)) {
                player.getMainHandItem().getCapability(ItemSlashBlade.BLADESTATE).map(state ->{
                    state.setKillCount(state.getKillCount()+1);
                    return 0;
                });
            }
        }
    }
    @SubscribeEvent
    public static void Mizar(LivingHurtEvent event){
        hurtEventHandleSe(event,(p,l,state)->{
            hurtEventAmountBase(event, 0.1f);
        },LBRSpecialEffectRegsitry.Mizar.getId());
    }


    @Override
    public Component getDescription() {
         return Component.translatable(this.getDescriptionId()).withStyle(ChatFormatting.GOLD);
    }
}


